package com.alongstudio.account.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.alongstudio.account.commons.exception.BusinessException;
import com.alongstudio.account.entity.Merchant;
import com.alongstudio.account.service.IMerchantService;

@Service(value="MerchantService")
public class MerchantService extends BaseService implements IMerchantService {

	private String className = MerchantService.class.getName();
	@Override
	public String createMerchant(com.alongstudio.account.entity.Merchant merchant) throws BusinessException {
		try {
			dao.create(merchant);
		}
		catch (Exception e) {
			throw new BusinessException(className, e);
		}

		return merchant.getId();
	}

	@Override
	public List<Merchant> findAllMerchant(String userId) throws BusinessException {
		List<Merchant> list = null;
//		try {
//			list = dao.query("from Merchant m where m.clientUser.id=" + userId);
//		}
//		catch (Exception e) {
//			throw new BusinessException(className, e);
//		}
		return list;
	}

	@Override
	public boolean updateMerchant(Merchant merchant) throws BusinessException {
		try {
			dao.update(merchant);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException(className, e);
		}
	}

	@Override
	public boolean deleteMerchant(String id) throws BusinessException {
		try {
			dao.deleteByPk(Merchant.class, id);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException(className, e);
		}
	}

}
